/*
 * Copyright 2009 Eat Local Food, LLC
 * Copyright (c) 2007 osCommerce (this file was written after
 * code review of osCommerce).
 *
 * This file is part of gwtCommerce.
 *
 * gwtCommerce is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 2 of the License, or
 * (at your option) any later version.
 *
 * gwtCommerce is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with gwtCommerce.  If not, see <http://www.gnu.org/licenses/>.
 */
package com.elf.gwt.common.client.model;

import java.util.Date;

import com.google.gwt.json.client.JSONObject;

public class CurrencyModel extends AbstractModel
{
	protected String code;
	protected boolean defaultCode;
	protected int id = 0; 
	protected String name;
	protected double value;
	protected Date dateUpdated;
	protected String symbolLeft;
	protected String symbolRight;
	protected String decimalPoint;
	protected String thousandsPoint;
	protected int decimalPlaces;


	public CurrencyModel(int id, String name, String code, double value, boolean defaultCode)
	{
		this.id = id;
		this.name = name;
		this.code = code;
		this.value = value;
		this.defaultCode = defaultCode;
		this.dateUpdated = null;

		symbolLeft = "";
		symbolRight = "";
		decimalPoint = "";
		thousandsPoint = "";
		decimalPlaces = 0;
	}
	
	public CurrencyModel(JSONObject jsonObject, String defaultCodeStr)
	{
		id = convertToInteger(jsonObject,"id");
		name = convertToString(jsonObject,"name");
		code = convertToString(jsonObject,"code");
		value = convertToDouble(jsonObject,"value");
		dateUpdated = convertToDate(jsonObject,"date_updated");

		symbolLeft = convertToString(jsonObject,"symbol_left");
		symbolRight = convertToString(jsonObject,"symbol_right");
		decimalPoint = convertToString(jsonObject,"decimal_point");
		thousandsPoint = convertToString(jsonObject,"thousands_point");
		decimalPlaces = convertToInteger(jsonObject,"decimal_places");
		
		defaultCode = false;
		if (defaultCodeStr.equals(code)) defaultCode = true;
	}

	public void update(CurrencyModel model)
	{
		id = model.getId();
		name = model.getName();
		code = model.getCode();
		value = model.getValue();
		defaultCode = model.isDefaultCode();

		symbolLeft = model.getSymbolLeft();
		symbolRight = model.getSymbolRight();
		decimalPoint = model.getDecimalPoint();
		thousandsPoint = model.getThousandsPoint();
		decimalPlaces = model.getDecimalPlaces();
	}
	
	public String getCode() {
		return code;
	}
	
	public int getId() {
		return id;
	}

	public String getName() {
		return name;
	}

	public double getValue() {
		return value;
	}
	
	public boolean isDefaultCode() {
		return defaultCode;
	}

	public Date getDateUpdated() {
		return dateUpdated;
	}

	public String getSymbolLeft() {
		return symbolLeft;
}

	public String getSymbolRight() {
		return symbolRight;
	}

	public String getDecimalPoint() {
		return decimalPoint;
	}

	public String getThousandsPoint() {
		return thousandsPoint;
	}

	public int getDecimalPlaces() {
		return decimalPlaces;
	}
}
